home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / tprolog.arc / SCRTCH.PRO < prev    next >
Text File  |  1991-08-03  |  1KB  |  47 lines

  1.  
  2. /*                      Scratch Pad Utility */
  3. domains
  4.        name = symbol
  5.  
  6. database
  7.         sp(name,real)
  8.  
  9. predicates
  10.          remember(name,real)
  11.          recall(name,real)
  12.          forget(name)
  13.          set_count(name)
  14.          count_up(name,real)
  15.          clr_sp
  16.          disp_sp
  17.          plus_sp(name,real,real)
  18.          minus_sp(name,real,real)
  19.  
  20. clauses
  21.        remember(Name,Value) :- asserta(sp(Name,Value)).
  22.  
  23.        forget(Name) :- retract(sp(Name,_)).
  24.  
  25.        recall(Name,Value) :- sp(Name,Value).
  26.  
  27.        set_count(Name) :- asserta(sp(Name,0)).
  28.  
  29.        count_up(Name,Value1) :- retract(sp(Name,Value)),
  30.                                 Value1=Value+1,
  31.                                 asserta(sp(Name,Value1)),!.
  32.  
  33.        clr_sp :- retract(sp(_,_)),fail.
  34.  
  35.        disp_sp :- sp(Name,Value),
  36.                   write(Name,"\t",Value),nl,fail.
  37.  
  38.        plus_sp(Name,Addend,Newvalue) :- recall(Name,Value),
  39.                                         Newvalue=Value+Addend,
  40.                                         forget(Name),
  41.                                         remember(Name,Newvalue).
  42.  
  43.        minus_sp(Name,Addend,Newvalue) :- recall(Name,Value),
  44.                                          Newvalue=Value-Addend,
  45.                                          forget(Name),
  46.                                          remember(Name,Newvalue).
  47.